﻿@model IEnumerable<Developer.Entity.Books>
@{
    Layout = null;
}

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="~/Content/UI/css/mui.min.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="~/Content/UI/css/mdui.min.css" />
    <style>
        h5 {
            margin-bottom: 10px;
        }

        img {
            width: 50%;
            float: left;
        }

        .detail {
            width: 45%;
            float: left;
            margin-left: 5%;
        }
    </style>
</head>

<body>
    <header class="mui-bar mui-bar-nav">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
        <h1 class="mui-title">在线预订</h1>
    </header>

    <div class="mui-content" style="padding-bottom: 100px;">
        @if (Model.Count() == 0)
        {
            <div class="mui-content" style="padding-bottom: 500px;">
                <h4 class="mdui-text-center" style="margin-top: 100px;">当前没有馆存大于0的图书哦~</h4>
            </div>
        }
        else
        {
            <ul class="mui-table-view mui-card">
                @{
                    foreach (var item in Model.Where(a=>a.IsAbort == false))
                    {
                        var country = string.Empty;
                        if (item.Author.Contains('】'))
                        {
                            country = item.Author.Split('】')[0];

                        }
                        else if (item.Author.Contains("]"))
                        {
                            country = item.Author.Split(']')[0].Split('[')[1];
                        }
                        else
                        {
                            country = item.Author;
                        }

                        <li class="mui-table-view-cell mui-collapse">
                            <a class="mui-navigate-right" href="#">@(item.Author.Contains('】') == true ? country + "】" + item.Name : (item.Author.Contains(']') == true ? "【" + country + "】" + item.Name : item.Name)  )</a>
                            <div class="mui-collapse-content">
                                <a href="/book/detail?bookId=@item.Id">
                                    <img src="@item.CoverImg" class="mdui-shadow-8">
                                </a>
                                <div class="detail">
                                    <h5><strong>书名：</strong>@item.Name</h5>
                                    <h5><strong>作者：</strong>@(item.Author.Contains('】') == true ? item.Author.Split('】')[1] : (item.Author.Contains(']') == true ? item.Author.Split(']')[1] : item.Author))</h5>
                                    <h5><strong>定价：</strong>@item.OriginPrice￥</h5>
                                    <h5><strong>预定价：</strong>@item.OrderPrice￥</h5>
                                    <h5><strong>ISBN：</strong>@item.ISBN</h5>
                                    <h5><strong>馆存：</strong>@item.BookGits.First().Remain</h5>
                                </div>
                                <div>

                                    <h4 style="float: right;margin-top:10%;color: red;font-family:'copperplate gothic light';" onclick="order(@item.Id)">点我预定</h4>

                                </div>
                            </div>
                        </li>
                        
                    }
                }

            </ul>

                    }

    </div>
    <script src="~/Content/scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Content/UI/js/mui.min.js"></script>
    <script type="text/javascript" src="~/Content/UI/js/mdui.min.js"></script>
    <script type="text/javascript">
        mui.init()

        function order(bid) {
            if (typeof (localStorage.user) == 'undefined') {
                //未登录
                mdui.snackbar({
                    message: '请先登录！',
                    buttonText: '登陆',
                    onClick: function () {
                        window.location("/account/login");
                    },
                    onButtonClick: function () {
                        window.location("/account/login");
                    },
                    onClose: function () {
                        window.location("/account/login");
                    }
                });
            } else {
                var uid = localStorage.user;
                $.ajax({
                    url: '/Book/AddOrder',
                    dataType: 'Json',
                    type: 'POST',
                    data: { 'uid': uid, 'bid': bid },
                    success: function (data) {
                        if (data.hasOwnProperty('error')) {
                            mdui.snackbar({
                                message: data['error']
                            });
                            return;
                        } else {
                            mdui.snackbar({
                                message: data['success']
                            });
                        }
                    },
                    error: function(){
                        mdui.snackbar({
                            message: '未知错误，请检查网络连接'
                        });
                    }
                });
            }
        }
    </script>
</body>

</html>
